<html>
<head><meta charset="utf-8"><title>const eval of SIMD ops · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html">const eval of SIMD ops</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214110009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214110009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214110009">(Oct 21 2020 at 20:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/131828-t-compiler/topic/Portable.20SIMD.20Compiler.20Support/near/213997272">said</a>:</p>
<blockquote>
<p>But I do concur that having MIR _understand_ vector operations is useful – it would at very least be a prerequisite for const-evaluation of simd code, I think?</p>
</blockquote>
<p>This was brought up here. I don't know what is required in order for that to happen, but I would be interested to know. It's out-of-scope for portable SIMD technically buuut</p>



<a name="214119024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214119024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214119024">(Oct 21 2020 at 21:48)</a>:</h4>
<p>We can do SIMD without MIR support, as long as all SIMD operations are restricted to intrinsic function invocations. Then we'd mark individual intrinsics as const fn and give them an impl. We've had some discussions about this in an issue <a href="https://github.com/rust-lang/const-eval">https://github.com/rust-lang/const-eval</a> . Basically I think the tenor was that we don't want to support SIMD, as any SIMD usage likely needs a code path for when SIMD is not supported and we can just use that path</p>



<a name="214146513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214146513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214146513">(Oct 22 2020 at 06:01)</a>:</h4>
<p><em>don't</em> want to?</p>



<a name="214148406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214148406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214148406">(Oct 22 2020 at 06:41)</a>:</h4>
<p>Well... according to <a href="https://github.com/rust-lang/const-eval/issues/7">https://github.com/rust-lang/const-eval/issues/7</a> there are multiple thousand different SIMD intrinsics that we'd need to support</p>



<a name="214148410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214148410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214148410">(Oct 22 2020 at 06:42)</a>:</h4>
<p>That doesn't seem realistic</p>



<a name="214157935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214157935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214157935">(Oct 22 2020 at 08:38)</a>:</h4>
<p>They are largely <em>insanely</em> programmatic and a consequence of the combinatoric nature of things... e.g. you get an intrinsic to reinterpret the vector register as a different bitpattern, so of course you get one for reinterpreting a vector register of u8s into f64s, oh and of course one for reinterpreting a register of f64s into u8s, and then f64 -&gt; f32, f32 -&gt; f64, f32 -&gt; u8... etc.</p>
<p>So for every ~100 or so new intrinsics added there's like one real new function.</p>



<a name="214272884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214272884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> jknodt <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214272884">(Oct 23 2020 at 04:36)</a>:</h4>
<p>is this asking about fixed size array operations, and replacing them with SIMD instructions where possible? I'm not sure if fixed size arrays are the same as the vector operations Nagisa is referring to, as this could be different if someone were for example to implement <code>Add for [T; N]</code></p>



<a name="214272966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214272966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214272966">(Oct 23 2020 at 04:38)</a>:</h4>
<p>No, this is not about implicit vectorization.</p>



<a name="214275182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214275182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214275182">(Oct 23 2020 at 05:26)</a>:</h4>
<p>so hold on. there are two things here:</p>
<p>1) portable simd being const evaluated. In this scenario, the operation is an abstract logical operation that doesn't make any guarantee about the precise cpu ops executed. Particularly with integer data ops, there's absolutely no reason to not make this all const fn beyond "we haven't had time yet".</p>
<p>2) arch intrinsics being const being const evaluated. In this case, the operation is generally a specific operation on a specific CPU and users might have specific expectations about what happens (flag side effects, or whatever), and so const evaluating arch intrinsics could be easily declared as something we don't make const fn.</p>



<a name="214276564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214276564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214276564">(Oct 23 2020 at 05:55)</a>:</h4>
<p>Oh yeah, the RVV thing has like a million and one flags for it, that's a good generic argument against const evaluating arch intrinsics.</p>



<a name="214339521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214339521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214339521">(Oct 23 2020 at 17:07)</a>:</h4>
<p>also for miri it would likely be much easier to hook those portable SIMD operations than implementation all the platform-specific ones</p>



<a name="214339576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214339576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214339576">(Oct 23 2020 at 17:07)</a>:</h4>
<p>so we'd need some good way to say "this is a <code>const fn</code> but to run it at CTFE time, dont execute its MIR body... rather run a specialized shim in the interpreter"</p>



<a name="214339665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214339665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214339665">(Oct 23 2020 at 17:08)</a>:</h4>
<p>we have a few ad-hoc cases of this so far... some functions for starting panics, and <code>align_offset</code></p>



<a name="214339890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214339890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214339890">(Oct 23 2020 at 17:10)</a>:</h4>
<p>another way is to stop doing these special cases and introduce some way to specify both a CTFE function and a runtime version in the surface language (this can be as simple as an intrinsic that takes two function definitions and calls one of them depending on the context)</p>



<a name="214340128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214340128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214340128">(Oct 23 2020 at 17:12)</a>:</h4>
<p><code>#[rustc_const_fn_shim=other_fn]</code> :P</p>



<a name="214340148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214340148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214340148">(Oct 23 2020 at 17:13)</a>:</h4>
<p>I guess I was imagining this to be something internal, not available to users</p>



<a name="214340194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214340194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214340194">(Oct 23 2020 at 17:13)</a>:</h4>
<p>I dont know if we are quite ready to open the floodgates to letting users do case-distinction on runtime vs compiletme execuction^^</p>



<a name="214340299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214340299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214340299">(Oct 23 2020 at 17:14)</a>:</h4>
<p>heh, good argument</p>



<a name="214340313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214340313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214340313">(Oct 23 2020 at 17:14)</a>:</h4>
<p>but I think if it's forever unstable... it could be ok</p>



<a name="214340326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214340326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214340326">(Oct 23 2020 at 17:14)</a>:</h4>
<p>I like writing the shims in Rust</p>



<a name="214343498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214343498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214343498">(Oct 23 2020 at 17:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/const.20eval.20of.20SIMD.20ops/near/214340326">said</a>:</p>
<blockquote>
<p>I like writing the shims in Rust</p>
</blockquote>
<p>yes that would be very useful (but then we couldn't use it to replace the existing ad-hoc things... seems fine though)</p>



<a name="214343688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214343688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214343688">(Oct 23 2020 at 17:43)</a>:</h4>
<p>And then you can fuzz them to make sure that they are the same.</p>



<a name="214343714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214343714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214343714">(Oct 23 2020 at 17:43)</a>:</h4>
<p>And opt in to the shims on other platforms.</p>



<a name="214345330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214345330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214345330">(Oct 23 2020 at 17:57)</a>:</h4>
<p>@RalfJ how would this affect the shims I'm familiar with?</p>



<a name="214345506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214345506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214345506">(Oct 23 2020 at 17:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="132916">Christian Poveda</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/const.20eval.20of.20SIMD.20ops/near/214345330">said</a>:</p>
<blockquote>
<p>@RalfJ how would this affect the shims I'm familiar with?</p>
</blockquote>
<p>not at all I think, seems rather unrelated</p>



<a name="214345521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214345521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214345521">(Oct 23 2020 at 17:58)</a>:</h4>
<p>we will <em>not</em> shim <code>open</code> for CTFE :P</p>



<a name="214345567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214345567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214345567">(Oct 23 2020 at 17:58)</a>:</h4>
<p>heh</p>



<a name="214345591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214345591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214345591">(Oct 23 2020 at 17:58)</a>:</h4>
<p>I hope</p>



<a name="214345799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214345799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214345799">(Oct 23 2020 at 18:00)</a>:</h4>
<p>ok but there are  some platform specific shims that are deterministic, like all the <code>math</code> functions and so on, are those evaluated in the same way in miri and in CTFE?</p>



<a name="214345990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214345990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214345990">(Oct 23 2020 at 18:01)</a>:</h4>
<p>or are those shims completely unrelated to how simd ops would be shimmed?</p>



<a name="214346561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214346561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214346561">(Oct 23 2020 at 18:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="132916">Christian Poveda</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/const.20eval.20of.20SIMD.20ops/near/214345799">said</a>:</p>
<blockquote>
<p>ok but there are  some platform specific shims that are deterministic, like all the <code>math</code> functions and so on, are those evaluated in the same way in miri and in CTFE?</p>
</blockquote>
<p>oh but are they deterministic? <code>math</code> means floating point means a high chance of weirdness^^</p>



<a name="214346638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214346638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214346638">(Oct 23 2020 at 18:06)</a>:</h4>
<p><code>sin</code> and <code>cos</code> and friends are not deterministic accross platforms I am afraid</p>



<a name="214346669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214346669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214346669">(Oct 23 2020 at 18:06)</a>:</h4>
<p>that's true</p>



<a name="214346702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214346702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214346702">(Oct 23 2020 at 18:06)</a>:</h4>
<p>so for now let's stick to integer SIMD</p>



<a name="214346757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214346757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214346757">(Oct 23 2020 at 18:07)</a>:</h4>
<p>for FP SIMD, we should await the conclusion of <a href="https://github.com/rust-lang/rust/issues/77745">https://github.com/rust-lang/rust/issues/77745</a></p>



<a name="214355602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214355602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214355602">(Oct 23 2020 at 19:24)</a>:</h4>
<p>Can MIRI get the MIR for compiler-builtins functions?  That might be another way to write them in rust, doing the shimming at a different level...</p>
<p>(Like a mir-opt pass that has a big table of <code>rust-intrinsic</code> <code>Call</code>s to replace with <code>Call</code>s to compiler-builtins...)</p>



<a name="214357322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214357322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214357322">(Oct 23 2020 at 19:42)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> not entirely sure what you mean... but miri can load the mir of any function if it can be looked up by path</p>



<a name="214405348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214405348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214405348">(Oct 24 2020 at 02:46)</a>:</h4>
<p>I think that very simple ops like Add could possibly be const fn for floats, but as I mentioned, the transcendents maybe never.</p>



<a name="214410755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214410755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214410755">(Oct 24 2020 at 05:34)</a>:</h4>
<p>As i understand it, the issue there is something like: even though <code>sin</code> and <code>cos</code> are computed via normal add and mul (etc), the exact formula used can vary from platform to platform, and so it becomes inconsistent. is that it?</p>



<a name="214411806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214411806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214411806">(Oct 24 2020 at 06:15)</a>:</h4>
<p>Yes, and whether there's hardware support or not.</p>



<a name="214415814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214415814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214415814">(Oct 24 2020 at 08:39)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> I think the core problem is <a href="https://en.wikipedia.org/wiki/Rounding#Table-maker's_dilemma">https://en.wikipedia.org/wiki/Rounding#Table-maker's_dilemma</a></p>
<p>For some operations (including, importantly, <code>+-*/</code>) there are known efficient ways to compute it to within ½ULP, so Rust should just require that and allow it in const (if NAN handling can ever be rationalized in const, TBD).  But for some things, even getting close is a major challenge.  For example, imagine calculating <code>tan(1e308)</code> to even one sigfig -- <code>f64::PI</code> is nowhere even close to the amount of precision you need just to get the sign right.</p>



<a name="214417201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214417201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214417201">(Oct 24 2020 at 09:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281757">Jubilee</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/const.20eval.20of.20SIMD.20ops/near/214405348">said</a>:</p>
<blockquote>
<p>I think that very simple ops like Add could possibly be const fn for floats, but as I mentioned, the transcendents maybe never.</p>
</blockquote>
<p>the problem with adds is what we have to say what happens for NaNs... and that turns out to be quite hard to do  if we want to be consistent with target platforms and with what LLVM optimizations might do :/</p>



<a name="214461228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214461228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214461228">(Oct 25 2020 at 01:40)</a>:</h4>
<blockquote>
<p>Standards for languages intended to reproduce results exactly on all platforms are expected to specify behavior more tightly than do standards for languages intended to maximize performance on every platform.</p>
</blockquote>
<p>no kidding, huh.</p>



<a name="214466910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214466910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214466910">(Oct 25 2020 at 04:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/const.20eval.20of.20SIMD.20ops/near/214415814">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> I think the core problem is <a href="https://en.wikipedia.org/wiki/Rounding#Table-maker's_dilemma">https://en.wikipedia.org/wiki/Rounding#Table-maker's_dilemma</a></p>
<p>For some operations (including, importantly, <code>+-*/</code>) there are known efficient ways to compute it to within ½ULP, so Rust should just require that and allow it in const (if NAN handling can ever be rationalized in const, TBD).  But for some things, even getting close is a major challenge.  For example, imagine calculating <code>tan(1e308)</code> to even one sigfig -- <code>f64::PI</code> is nowhere even close to the amount of precision you need just to get the sign right.</p>
</blockquote>
<p>One of the reasons I like sinpi/cospi/tanpi much better -- range reduction is trivial since you don't need several hundred digits of pi to produce an accurate result.</p>



<a name="214507879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214507879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214507879">(Oct 25 2020 at 19:37)</a>:</h4>
<p>having just gone through IEEE754-2019 for my first pass, I think we kind of will have to define either a subset or extension of the language that allows floats to be const-eval'd but that we might be able to do it.</p>



<a name="214508252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214508252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214508252">(Oct 25 2020 at 19:44)</a>:</h4>
<p>I think that solving janky platform support will actually become saner when we have a nascent story for how we would like it to look. We're currently stuck in what Kahan described as the trap of</p>
<blockquote>
<p>Now atrophy threatens features of  IEEE 754  caught in a vicious circle:<br>
   - Those features lack support in programming languages and compilers,<br>
   - so those features are mishandled and/or practically unusable,<br>
   - so those features are little known and less in demand,  and so<br>
   - those features lack support in programming languages and compilers</p>
</blockquote>



<a name="214526134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20eval%20of%20SIMD%20ops/near/214526134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20eval.20of.20SIMD.20ops.html#214526134">(Oct 26 2020 at 02:17)</a>:</h4>
<p><span class="user-mention" data-user-id="229517">@Jacob Lifshay</span> Agreed.  Would be great to have those in std!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>